﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VINETLIFE.BL;
using VINETLIFE.DO;
using System.Data;

namespace VINETLIFE.Module
{
    public partial class ucHomeNews : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rptHomeNewCateDataSource();
            }
        }

        protected void rptHomeNewCate_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView drv = (DataRowView)e.Item.DataItem;

                Repeater rptHomeNews = (Repeater)e.Item.FindControl("rptHomeNews");

                int categoryID = int.Parse(drv["CategoryID"].ToString());

                rptHomeNews.DataSource = new cmsArticleBL().SelectHomepage(categoryID);
                rptHomeNews.DataBind();
            }
        }
        private void rptHomeNewCateDataSource()
        {
            rptHomeNewCate.DataSource = new cmsCategoryBL().SelectHomepageByType(1, false);
            rptHomeNewCate.DataBind();
        }

        protected string FriendlyUrl(string s)
        {
            return Ultility.Change_AV(s);
        }
        public string WordCut(string text)
        {
            return Ultility.WordCut(text, 100, new char[] { ' ', '.', ',', ';' }) + "...";
        }
    }
}